using System;
using System.Text.RegularExpressions;
using ITProf.Applications.pdb2gac.Enums;

namespace ITProf.Applications.pdb2gac.GacUtil
{
    internal static class GacUtilOutputParser
    {
        internal static Version ParseVersion(string gacutilOutput)
        {
            Regex regex = new Regex("Version={1}([0-9.]+)");
            return new Version(regex.Match(gacutilOutput).Groups[1].Value);
        }

        internal static string ParsePublicKeyToken(string gacutilOutput)
        {
            Regex regex = new Regex("PublicKeyToken=([a-z0-9]*)");
            return regex.Match(gacutilOutput).Groups[1].Value;
        }

        internal static GacAssemblyProcessorArchitecture ParseProcessorArchitecture(string gacutilOutput)
        {
            Regex regex = new Regex("processorArchitecture=(x86|x64|MSIL)");
            string pa = regex.Match(gacutilOutput).Groups[1].Value;
            return (GacAssemblyProcessorArchitecture) Enum.Parse(typeof (GacAssemblyProcessorArchitecture), pa);
        }

        internal static string ParseCulture(string gacutilOutput)
        {
            Regex regex = new Regex("Culture=([a-zA-Z0-9]*)");
            string culture = regex.Match(gacutilOutput).Groups[1].Value;
            return culture.Replace("neutral", "");
        }
    }
}